using System.Data;
using PCSComProduct.Costing.DS;
using PCSComUtils.MasterSetup.DS;
using PCSComProduct.Items.DS;
using System.Transactions;
using PCSComUtils.DataContext;
using System.Collections.Generic;
using System.Linq;
using PCSComUtils.DataAccess;
namespace PCSComProduct.Items.BO
{
    public class RoutingBO //: IRoutingBO
    {
        private const string THIS = "PCSComProduct.Items.BO.RoutingBO";
        public RoutingBO()
        {
            //
            // TODO: Add constructor logic here
            //
        }



        public void Add(object pObjectDetail)
        {
            // TODO:  Add RoutingBO.Add implementation

        }

        public void Delete(object pObjectVO)
        {
            // TODO:  Add RoutingBO.Delete implementation

        }

        public object GetObjectVO(int pintID, string VOclass)
        {
            // TODO:  Add RoutingBO.GetObjectVO implementation
            return null;
        }

        //**************************************************************************              
        ///    <Description>
        ///       This method uses to 
        ///    </Description>
        ///    <Inputs>
        ///            
        ///    </Inputs>
        ///    <Outputs>
        ///       
        ///    </Outputs>
        ///    <Returns>
        ///       
        ///    </Returns>
        ///    <Authors>
        ///       Hoang Trung Son - iSphere software
        ///    </Authors>
        ///    <History>
        ///       Wednesday, February 02, 2005
        ///    </History>
        ///    <Notes>
        ///    </Notes>
        //**************************************************************************
        public void Update(object pObjectDetail)
        {
            // TODO:  Add RoutingBO.Update implementation

        }

        //**************************************************************************              
        ///    <Description>
        ///       This method uses to 
        ///    </Description>
        ///    <Inputs>
        ///            
        ///    </Inputs>
        ///    <Outputs>
        ///       
        ///    </Outputs>
        ///    <Returns>
        ///       
        ///    </Returns>
        ///    <Authors>
        ///       Hoang Trung Son - iSphere software
        ///    </Authors>
        ///    <History>
        ///       Wednesday, February 02, 2005
        ///    </History>
        ///    <Notes>
        ///    </Notes>
        //**************************************************************************
        //[AutoComplete(true)]
        public void UpdateDataSet(DataSet dstData)
        {
            ITM_RoutingDS dsRouting = new ITM_RoutingDS();
            dsRouting.UpdateDataSet(dstData);
        }
        public void UpdateRouting(List<ITM_Routing> listRouting, ITM_Product voProduct)
        {
            using (var trans = new TransactionScope())
            {
                using (var db = new PCSDataContext(Utils.Instance.ConnectionString))
                {
                    var listRoutingDel = db.ITM_Routings.Where(e => e.ProductID==voProduct.ProductID);
                    if (listRoutingDel.Count() > 0) { db.ITM_Routings.DeleteAllOnSubmit(listRoutingDel); db.SubmitChanges(); }
                    db.ITM_Routings.InsertAllOnSubmit(listRouting);
                    db.SubmitChanges();
                    var obj = db.ITM_Products.SingleOrDefault(e => e.ProductID==voProduct.ProductID);
                    obj.RoutingDescription = voProduct.RoutingDescription;
                    obj.RoutingIncrement = voProduct.RoutingIncrement;
                    obj.ProductionLineID = voProduct.ProductionLineID;
                    obj.CCNID = voProduct.CCNID;
                    obj.ProductGroupID = voProduct.ProductGroupID;
                    obj.CostCenterRateMasterID = voProduct.CostCenterRateMasterID;
                    db.SubmitChanges();
                    trans.Complete();
                }
            }
        }

        public void Delete(ITM_Product voProduct)
        {
            using (var trans = new TransactionScope())
            {
                using (var db = new PCSDataContext(Utils.Instance.ConnectionString))
                {
                    var listRoutingDel = db.ITM_Routings.Where(e => e.ProductID == voProduct.ProductID);
                    if (listRoutingDel.Count() > 0) { db.ITM_Routings.DeleteAllOnSubmit(listRoutingDel); db.SubmitChanges(); }
                   
                    
                    var obj = db.ITM_Products.SingleOrDefault(e => e.ProductID == voProduct.ProductID);
                    obj.RoutingDescription =null;
                    obj.RoutingIncrement =null;
                    obj.ProductionLineID = null;
                    obj.CCNID = voProduct.CCNID;
                    obj.ProductGroupID =null;
                    obj.CostCenterRateMasterID = null;
                    db.SubmitChanges();
                    trans.Complete();
                }
            }
        }       

        //**************************************************************************              
        ///    <Description>
        ///       This method uses to list work center
        ///    </Description>
        ///    <Inputs>
        ///            
        ///    </Inputs>
        ///    <Outputs>
        ///       
        ///    </Outputs>
        ///    <Returns>
        ///       
        ///    </Returns>
        ///    <Authors>
        ///       Hoang Trung Son - iSphere software
        ///    </Authors>
        ///    <History>
        ///       Monday, January 24, 2005
        ///    </History>
        ///    <Notes>
        ///    </Notes>
        //**************************************************************************
        //[AutoComplete(true)]
        public DataSet ListWorkCenter()
        {
            MST_WorkCenterDS dsWorkCenter = new MST_WorkCenterDS();
            return dsWorkCenter.ListForCombo();
        }

        //**************************************************************************              
        ///    <Description>
        ///       This method uses to 
        ///    </Description>
        ///    <Inputs>
        ///            
        ///    </Inputs>
        ///    <Outputs>
        ///       
        ///    </Outputs>
        ///    <Returns>
        ///       
        ///    </Returns>
        ///    <Authors>
        ///       Hoang Trung Son - iSphere software
        ///    </Authors>
        ///    <History>
        ///       Monday, January 24, 2005
        ///    </History>
        ///    <Notes>
        ///    </Notes>
        //**************************************************************************
        //[AutoComplete(true)]
        public DataSet ListRoutingStatus()
        {
            ITM_RoutingStatusDS dsRoutingStatus = new ITM_RoutingStatusDS();
            return dsRoutingStatus.List();
        }

        //**************************************************************************              
        ///    <Description>
        ///       This method uses to 
        ///    </Description>
        ///    <Inputs>
        ///            
        ///    </Inputs>
        ///    <Outputs>
        ///       
        ///    </Outputs>
        ///    <Returns>
        ///       
        ///    </Returns>
        ///    <Authors>
        ///       Hoang Trung Son - iSphere software
        ///    </Authors>
        ///    <History>
        ///       Monday, January 24, 2005
        ///    </History>
        ///    <Notes>
        ///    </Notes>
        //**************************************************************************
        //[AutoComplete(true)]
        public DataSet ListCostCenter()
        {
            ITM_CostCenterDS dsCostCenter = new ITM_CostCenterDS();
            return dsCostCenter.List();
        }

        //**************************************************************************              
        ///    <Description>
        ///       This method uses to 
        ///    </Description>
        ///    <Inputs>
        ///            
        ///    </Inputs>
        ///    <Outputs>
        ///       
        ///    </Outputs>
        ///    <Returns>
        ///       
        ///    </Returns>
        ///    <Authors>
        ///       Hoang Trung Son - iSphere software
        ///    </Authors>
        ///    <History>
        ///       Monday, January 24, 2005
        ///    </History>
        ///    <Notes>
        ///    </Notes>
        //**************************************************************************
        //[AutoComplete(true)]
        public DataSet ListRoutingByProduct(int pintProductID)
        {
            ITM_RoutingDS dsRouting = new ITM_RoutingDS();
            return dsRouting.ListRoutingByProduct(pintProductID);
        }
        //**************************************************************************              
        ///    <Description>
        ///       This method uses to 
        ///    </Description>
        ///    <Inputs>
        ///            
        ///    </Inputs>
        ///    <Outputs>
        ///       
        ///    </Outputs>
        ///    <Returns>
        ///       
        ///    </Returns>
        ///    <Authors>
        ///       Hoang Trung Son - iSphere software
        ///    </Authors>
        ///    <History>
        ///       Thursday, January 27, 2005
        ///    </History>
        ///    <Notes>
        ///    </Notes>
        //**************************************************************************
        //[AutoComplete(true)]
        public DataSet ListFunction()
        {
            MST_FunctionDS dsFunction = new MST_FunctionDS();
            return dsFunction.List();
        }

        //**************************************************************************              
        ///    <Description>
        ///       This method uses to 
        ///    </Description>
        ///    <Inputs>
        ///            
        ///    </Inputs>
        ///    <Outputs>
        ///       
        ///    </Outputs>
        ///    <Returns>
        ///       
        ///    </Returns>
        ///    <Authors>
        ///       Hoang Trung Son - iSphere software
        ///    </Authors>
        ///    <History>
        ///       Thursday, February 03, 2005
        ///    </History>
        ///    <Notes>
        ///    </Notes>
        //**************************************************************************
        //[AutoComplete(true)]
        public DataSet ListParty()
        {
            MST_PartyDS dsParty = new MST_PartyDS();
            return dsParty.List();
        }

        //**************************************************************************              
        ///    <Description>
        ///       This method uses to 
        ///    </Description>
        ///    <Inputs>
        ///            
        ///    </Inputs>
        ///    <Outputs>
        ///       
        ///    </Outputs>
        ///    <Returns>
        ///       
        ///    </Returns>
        ///    <Authors>
        ///       Hoang Trung Son - iSphere software
        ///    </Authors>
        ///    <History>
        ///       Wednesday, February 02, 2005
        ///    </History>
        ///    <Notes>
        ///    </Notes>
        //**************************************************************************
        //[AutoComplete(true)]
        public void UpdateRoutingDescription(object pobjProduct)
        {
            ITM_RoutingDS dsRouting = new ITM_RoutingDS();
            dsRouting.UpdateRoutingDescription(pobjProduct);
        }

        /// <summary>
        /// Get Production Line information from ID
        /// </summary>
        /// <param name="pintProductionLineID">Production Line ID</param>
        /// <returns>Production Line Code</returns>
        //[AutoComplete(true)]
        public string GetProductionLineCode(int pintProductionLineID)
        {
            ITM_RoutingDS dsRouting = new ITM_RoutingDS();
            return dsRouting.GetProductionLineCode(pintProductionLineID);
        }
        /// <summary>
        /// Get Product Group Code from ID
        /// </summary>
        /// <param name="pintProductGroupID">ProductGroup ID</param>
        /// <returns>Product Group Code</returns>
        //[AutoComplete(true)]
        public string GetProductGroupCode(int pintProductGroupID)
        {
            ITM_RoutingDS dsRouting = new ITM_RoutingDS();
            return dsRouting.GetProductGroupCode(pintProductGroupID);
        }
        /// <summary>
        /// Get Cost Center Rate
        /// </summary>
        /// <param name="pintCostCenterMasterID">CostCenterRate Master ID</param>
        /// <returns>Cost Center Rate Code</returns>
        //[AutoComplete(true)]
        public string GetCostCenterMasterCode(int pintCostCenterMasterID)
        {
            ITM_RoutingDS dsRouting = new ITM_RoutingDS();
            return dsRouting.GetCostCenterMasterCode(pintCostCenterMasterID);
        }
        //[AutoComplete(true)]
        public bool IsWorkCenterInProductionLine(int pintProductionLineID, int pintWorkCenterID)
        {
            ITM_RoutingDS dsRouting = new ITM_RoutingDS();
            return dsRouting.IsWorkCenterInProductionLine(pintProductionLineID, pintWorkCenterID);
        }
        //[AutoComplete(true)]
        public bool HasWorkCenterNotInProductionLine(int pintProductionLineID, string pstrWorkCenterIDs)
        {
            ITM_RoutingDS dsRouting = new ITM_RoutingDS();
            return dsRouting.HasWorkCenterNotInProductionLine(pintProductionLineID, pstrWorkCenterIDs);
        }
    }
}
